Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <head> <script src="../../ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> $(document).ready(function(){ $("p:nth-last-child(3n+2)").css("background-color","yellow"); }); </script> </head> <body> <p>The p:nth-child(3n+2) selects each 3rd paragraph, starting at the last 2nd child element (in this case the eight p element). <div style="border:1px solid;"> <p>The first paragraph.</p> <p>The second paragraph.</p> <p>The third paragraph.</p> <p>The fourth paragraph.</p> <p>The fifth paragraph.</p> <p>The sixth paragraph.</p> <p>The seventh paragraph.</p> <p>The eight paragraph.</p> <span>This is a span element.</span> </div><br> </body> <!-- Mirrored from www.w3schools.com/jquery/tryit.asp?filename=tryjquery_sel_nthlastchild_formula by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:08:13 GMT --> </html>
Result:
Try it Yourself - © w3schools.com